package cn.jdy.plugins.wap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.authority.entity.User;
import cn.jdy.authority.entity.UserRole;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.framework.util.NginxPurgeCacheUtil;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.plugins.admin.util.PowerUtil;
import cn.jdy.plugins.entity.Chat;
import cn.jdy.plugins.entity.CheckLive;
import cn.jdy.plugins.entity.Live;
import cn.jdy.plugins.entity.SecretKeyCet;
import cn.jdy.plugins.service.ChatService;
import cn.jdy.plugins.service.CheckLiveService;
import cn.jdy.plugins.service.LiveService;
import cn.jdy.plugins.service.SecretKeyCetService;

/**
 * @title  审核管理
 * @author jga
 * @since  2017-9-23
 */

@Controller
@RequestMapping("/checkLive")
public class CheckLiveCtrl extends BaseCtrl{
	@Autowired
	private CheckLiveService checkLiveService;
	@Autowired
	private LiveService liveService;
	//默认列表路径
	@Autowired
	protected HttpSession session;
	@Autowired
	private ChatService chatService;
	@Autowired
	private SecretKeyCetService secretKeyCetService;
	/**
	 * 审核
	 * @return
	 */
	@RequestMapping("/addcheckLiveopens")
	@ResponseBody
	public Map<String, Object> addcheckLiveopens(String liveid,String userOpenId,String userNickName,String name,String phone) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		try {
		CheckLive cli=	new CheckLive();
		cli.setSendStatus("0");
		cli.setLiveId(Long.valueOf(liveid));
		cli.setUserOpenId(userOpenId);
		cli.setUserNickName(userNickName);
		cli.setPhone(phone);
		cli.setName(name);
		cli.setCreateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));
			this.checkLiveService.save(cli);
			jsonMap.put("msg", "成功");

		
		} catch(Exception e) {
			jsonMap.put("dataList", "失败");
			BaseLog.e(getClass(), "删除异常！", e);
		}
		return jsonMap;
	}


	/**
	 * 从法律云来的连接
	 * @return
	 */
	@RequestMapping("/checkLiveopens")
	public ModelAndView checkLiveopens(long liveid,String passwrod,String openid ) {
		ModelAndView mv = new ModelAndView();
		try {
		 if(passwrod.equals("8279021011")){
				SecretKeyCet skc=new SecretKeyCet();
				skc.setCreateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));
				skc.setUserOpenId(openid);
				skc.setUserNickName("");
				skc.setPasswork(passwrod);
				skc.setIsStatus("1");
				skc.setLiveId(liveid);
				secretKeyCetService.save(skc);
			mv.setViewName("redirect:/live/index/"+liveid);
			//mv.setViewName("redirect:/chat/edit/"+liveid);
		 }
 

		
		} catch(Exception e) {
			mv.setViewName("redirect:/index/"+liveid);
			BaseLog.e(getClass(), "删除异常！", e);
		}
		return mv;
	}

	  
}
